Shell 打印输出
在Shell脚本语言之中,主要分为echo 和 print两个输出语法,其中echo最为常见,本章主要介绍echo和print语法的输出和方法:
echo
echo语法可以显示普通的字符串、打印变量、方法等,其在Shell中最为常用:
打印普通字符串
1 2
| #! /bin/bash echo 'Hello,world'
|
打印变量
1 2 3
| #! /bin/bash var='Hello,world' echo $var
|
echo 方法
| ID |
DA |
FA |
| \ |
转义 |
echo “"Hello,world” |
| -e |
开启转义 |
echo -e “null” |
| \n |
换行 |
echo -e “null \n” |
| \c |
显示不换行 |
echo -e “null \c” |
printf
printf 是在Shell之中不为常用但依然需要用的方法,需要注意的是,printf命令是模仿C程序库(library)中的printf()程序
输出普通字符串
1 2
| #! /bin/bash printf 'hello,world'
|
输出变量
1 2 3
| #! /bin/bash var='world!' printf $var
|
printf 方法
| ID |
DA |
| \ |
转义 |
| \n |
换行 |
| \r |
回车 |
| \f |
换页 |
⬅️ Go back